package ca.psquared.superbrixgame.key;

import java.util.ArrayList;

public class KeyHandler {
    private ArrayList UserInputActions;

    public KeyHandler(){
        UserInputActions = new ArrayList();
    }

    public void registerUserInputAction(IKeyAction userInputAction) {
        UserInputActions.add(userInputAction);
    }

    public void removeUserInputAction(IKeyAction userInputAction) {
        int i = UserInputActions.indexOf(userInputAction);
        if (i >= 0) {
            UserInputActions.remove(i);
        }
    }

    public void keyPressed(int key) {
        for (int i = 0; i < UserInputActions.size(); i++) {
            IKeyAction userInputAction = (IKeyAction)UserInputActions.get(i);
            userInputAction.keyPressed(key);
        }
    }
    public void keyReleased(int key) {
        for (int i = 0; i < UserInputActions.size(); i++) {
            IKeyAction userInputAction = (IKeyAction)UserInputActions.get(i);
            userInputAction.keyReleased(key);
        }
    }
}
